/** @file MessageBox.qml
@brief Messagebox with confirmation button.

@todo Update the object with the Geometry methods
@todo Complete the messagebox customization

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

import QtQuick 1.0
import "Theme.js" as JsObj
import "Math.js" as JMath

Rectangle {
    id: formbackground

    signal objClicked // Button signal

    width: objLoad.getWidth(); height: objLoad.getHeight()
    color: "#ffffff";
    radius: JMath.mb_formRadius;
    border.width: JMath.mb_formBorder
    border.color: "#666666"

    // Choice buttons
    Row {
        id: buttons

        spacing: JMath.mb_formSpacing
        width: JMath.getMsgBoxBtnWidth(formbackground.width);
        visible: true

        anchors {
            bottom: formbackground.bottom;
            bottomMargin: JMath.getMsgBoxBtnBottomMargin();
            horizontalCenter: formbackground.horizontalCenter
        }

        // Confirm button
        BorderImage {
            id: button

            source: JsObj.getButton(objLoad.getTheme()); clip: true
            border { left: 10; top: 10; right: 10; bottom: 10 }

            width: parent.width //JMath.getMsgBoxBtnWidth(formbackground.width);
            height: JMath.getMsgBoxBtnHeight(formbackground.height);

            // Shade is set over the button image when it is presed
            Rectangle { id: shade; anchors.fill: button; radius: 5; color: "black"; opacity: 0 }

            // Font Size is set based on the button shorter side
            Text {
                id: buttonText
                anchors.centerIn: button;
                font.pixelSize: button.width > button.height ? button.height * .5 : button.width * .5
                text: objLoad.getString();
                style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true
            }

            MouseArea {
                id: mouseArea
                anchors.fill: parent
                onClicked: { formbackground.objClicked(); }
            }

            // When button is pressed the shade changes
            states: State {
                name: "pressed"; when: mouseArea.pressed == true
                PropertyChanges { target: shade; opacity: .2 }
            }
        }
    }

    // Message text
    Text {
        id: textIntro
        width: objLoad.getWidth()
        anchors.top: formbackground.top
        anchors.topMargin: 30 // banner size
        anchors.left: formbackground.left
        anchors.right: formbackground.right
        anchors.leftMargin: 20
        anchors.rightMargin: 20
        wrapMode: TextEdit.Wrap
        text: objLoad.getMessage();
        font.weight: Font.Bold
    }
}
